package cn.itcast.order.web;

import cn.itcast.order.listen.MyEventPublisher;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.service.OrderService;
import com.alibaba.nacos.common.notify.EventPublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {

   @Autowired
   private RestTemplate restTemplate;
   @Autowired
   private OrderService orderService;
   @Autowired
   private OrderMapper orderMapper;

   @Autowired
   private MyEventPublisher eventPublisher;


   @GetMapping("b")
    public String a(){
       return restTemplate.getForObject("http://userservice/user/hello",String.class);
   }

//   @PostMapping("/selectPage")
//   public R<IPage<Item>> iPage(@RequestBody @Validated PageParams<Item> params){
//      log.info("表查询的筛选条件：{}", params.getModel());
//      return R.success(orderService.selectALlData(params));
//   }

//   @PostMapping("p")
//   public Item p(){
//      Item byId = orderMapper.findById(1l);
//      return byId;
//   }
//    @GetMapping("{orderId}")
//    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {
//        // 根据id查询订单并返回
//        return orderService.queryOrderById(orderId);
//    }

   @GetMapping("c")
   public String c(){
      eventPublisher.publishEvent("Hello, this is a custom event!");
      return "ccc";
   }
}
